package com.hup.utils.commons.exception;

import com.hup.utils.commons.AssertApp;

/**
 * 由代码块捕获后,加入desc的异常
 *
 * @author hugan
 * @date 2019/8/24
 */
public class CauseException extends RuntimeException {

    public CauseException(String desc, Throwable cause) {
        super(buildMessage(desc, cause), cause);
    }

    @SuppressWarnings({"unchecked", "rawtypes"})
    private static String buildMessage(String desc, Throwable cause) {
        AssertApp.notNull(cause, "cause不能为空");
        ExceptionMsgParser parser = AppExceptionHandler.getParser(cause);
        if (parser != null) {
            String causeMsg = parser.getMsg(cause);
            return desc + causeMsg;
        }
        return desc + cause.getMessage();
    }

}
